﻿<navigation:Page x:Class="Groceries.Views.Items"
           xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
           xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
           xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
           xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
           mc:Ignorable="d"
           xmlns:navigation="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation"
           xmlns:datagrid="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data"
           xmlns:riacontrols="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Ria"
           xmlns:ds="clr-namespace:Groceries.Web.Services"
           xmlns:riadata="clr-namespace:System.Windows.Data;assembly=System.Windows.Controls.Ria"
           xmlns:dataform="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data.DataForm.Toolkit"
           xmlns:activity="clr-namespace:System.Windows.Controls;assembly=ActivityControl"
           d:DesignWidth="640" d:DesignHeight="480"
           Title="Items" xmlns:dataInput="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data.Input">
    <Grid x:Name="LayoutRoot">
        <Grid.Resources>
            <ds:GroceriesDomainContext x:Key="groceriesDomainContext" />
        </Grid.Resources>

        <riacontrols:DomainDataSource x:Name="itemsData" LoadSize="100" QueryName="GetItems" AutoLoad="True" DomainContext="{Binding Source={StaticResource groceriesDomainContext}}" >
            <riacontrols:DomainDataSource.FilterDescriptors>
                <riadata:FilterDescriptorCollection>
                    <riadata:FilterDescriptor PropertyPath="Name" Operator="Contains">
                        <riacontrols:ControlParameter ControlName="txtNameFilter" ParameterName="Text" RefreshEventName="TextChanged"/>
                    </riadata:FilterDescriptor>
                </riadata:FilterDescriptorCollection>
            </riacontrols:DomainDataSource.FilterDescriptors>
        </riacontrols:DomainDataSource>

        <ScrollViewer BorderThickness="0" VerticalScrollBarVisibility="Auto" Padding="0,12,0,12"
                Margin="-12">

            <activity:Activity IsActive="{Binding ElementName=itemsData,Path=IsBusy}">
                <StackPanel Margin="0,12,0,12" Orientation="Vertical">
                    <TextBlock Text="Items" Style="{StaticResource HeaderTextStyle}"/>
                    <StackPanel Orientation="Horizontal" HorizontalAlignment="Left" Margin="0,-16,0,0">
                        <TextBlock Text="Name Filter: " VerticalAlignment="Center"/>
                        <TextBox x:Name="txtNameFilter" Width="75" FontSize="11" Margin="4"/>
                    </StackPanel>
                    <datagrid:DataGrid x:Name="itemGrid" MinHeight="100"
                                   ItemsSource="{Binding ElementName=itemsData, Path=Data}" IsReadOnly="True">

                    </datagrid:DataGrid>

                    <datagrid:DataPager x:Name="itemPager" PageSize="20" Margin="0,-1,0,0" 
                                    Source="{Binding ElementName=itemsData,Path=Data}"/>

                    <dataform:DataForm x:Name="itemDetails" Header="Details" CurrentItem="{Binding ElementName=itemGrid,Path=SelectedItem}"
                    Margin="0,12,0,0" AutoCommit="False" AutoEdit="False">
                        <dataform:DataForm.EditTemplate>
                            <DataTemplate>
                                <StackPanel>
                                    <dataform:DataField Label="Name">
                                        <TextBox Text="{Binding Name,Mode=TwoWay}"/>
                                    </dataform:DataField>
                                    <dataform:DataField Label="Price">
                                        <TextBox Text="{Binding Price,Mode=TwoWay}"/>
                                    </dataform:DataField>
                                    <dataform:DataField Label="Supplier">
                                        <Grid>
                                          <ComboBox ItemsSource="{Binding Suppliers, Source={StaticResource groceriesDomainContext}}"
                                          SelectedItem="{Binding Supplier, Mode=TwoWay}"
                                          DisplayMemberPath="Name" />
                                        </Grid>
                                    </dataform:DataField>
                                </StackPanel>
                            </DataTemplate>
                        </dataform:DataForm.EditTemplate>
                    </dataform:DataForm>
                    <StackPanel Orientation="Horizontal" HorizontalAlignment="Right" Margin="0,12,0,0">
                        <Button Content="Save Changes" x:Name="buttonSave" Width="120" Height="23" Margin="4,0,0,0" Click="buttonSave_Click" />
                    </StackPanel>
                </StackPanel>
            </activity:Activity>
        </ScrollViewer>
    </Grid>
</navigation:Page>
